package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.SmsHomeRecommendProductMapper;
import com.mail.model.db.SmsHomeBrand;
import com.mail.model.db.SmsHomeRecommendProduct;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsHomeRecommendProductApiImpl implements SmsHomeRecommendProductApi{


    @Autowired
    private SmsHomeRecommendProductMapper smsHomeRecommendProductMapper;

    @Override
    public void save(SmsHomeRecommendProduct smsHomeRecommendProduct) {
        smsHomeRecommendProductMapper.insert(smsHomeRecommendProduct);
    }

    @Override
    public void deleteRecommendProduct(List<Long> ids) {
        smsHomeRecommendProductMapper.deleteBatchIds(ids);
    }

    @Override
    public Page<SmsHomeRecommendProduct> getRecommendProductByPage(Long pageNum, Long pageSize, String productName, Integer recommendStatus) {
        Page<SmsHomeRecommendProduct> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsHomeRecommendProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(productName), SmsHomeRecommendProduct::getProductName,productName)
                .eq(recommendStatus != null,SmsHomeRecommendProduct::getRecommendStatus,recommendStatus);
        Page<SmsHomeRecommendProduct> page1 = smsHomeRecommendProductMapper.selectPage(page,wrapper);
        return page1;
    }

    @Override
    public void updateRecommendProduct(Long id, Integer recommendStatus) {
        SmsHomeRecommendProduct smsHomeRecommendProduct = new SmsHomeRecommendProduct();
        smsHomeRecommendProduct.setId(id);
        smsHomeRecommendProduct.setRecommendStatus(recommendStatus);
        smsHomeRecommendProductMapper.updateById(smsHomeRecommendProduct);
    }

    @Override
    public void updateSortRecommendProduct(Long id, Integer sort) {
        SmsHomeRecommendProduct smsHomeRecommendProduct = new SmsHomeRecommendProduct();
        smsHomeRecommendProduct.setId(id);
        smsHomeRecommendProduct.setSort(sort);
        smsHomeRecommendProductMapper.updateById(smsHomeRecommendProduct);
    }
}
